package com.itheima.controller;

import com.itheima.pojo.*;
import com.itheima.service.ClazzService;
import com.itheima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @BelongsProject: project-springbootdemo02
 * @BelongsPackage: com.itheima.controller
 * @Author: jiangyi
 * @CreateTime: 2025-08-02  11:41
 * @Description: TODO
 * @Version: 1.0
 */
@Slf4j
@RequestMapping("/clazzs")
@RestController
public class ClazzController {

    @Autowired
    private ClazzService clazzService;
    @Autowired
    private EmpService empService;

    @GetMapping
    public Result clazzList(ClazzQueryParam clazzQueryParam){
        log.info("班级分页查询,参数:{}", clazzQueryParam);
        // 调用service分页查询
        PageResult pageResult = clazzService.clazzListPage(clazzQueryParam);

        return Result.success(pageResult);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("删除班级,id:{}", id);
        clazzService.deleteById(id);
        return Result.success();
    }

    @PostMapping
    public Result addClazz(@RequestBody Clazz clazz){
        log.info("添加班级,参数:{}", clazz);
        clazzService.addClazz(clazz);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id){
        log.info("编辑班级根据id回显数据,id:{}", id);
        Clazz clazz = clazzService.selectById(id);
        return Result.success(clazz);
    }

    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        log.info("更新班级信息,参数:{}", clazz);

        clazzService.update(clazz);
        return Result.success();
    }

    @GetMapping("/list")
    public Result findALl(){
        log.info("查询所有班级信息");
        List<Clazz> clazzList = clazzService.findAll();
        return Result.success(clazzList);
    }




}
